package com.ren.service.core.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ren.service.core.mapper.IntegralGradeMapper;
import com.ren.service.core.model.vo.IntegralGradeQueryRespVO;
import com.ren.service.core.model.vo.IntegralGradeSaveReqVO;
import com.ren.service.core.model.po.IntegralGradePO;
import com.ren.service.core.service.IIntegralGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author RenGaoshuai
 * @date 2023/8/7 16:25
 * @description
 */
@Service
public class IntegralGradeServiceImpl implements IIntegralGradeService {

    @Autowired
    private IntegralGradeMapper integralGradeMapper;

    @Override
    public List<IntegralGradePO> list() {
        Wrapper<IntegralGradePO> wrapper = new LambdaQueryWrapper<>();
        return integralGradeMapper.selectList(wrapper);
    }

    @Override
    public int removeById(Long id) {
        return integralGradeMapper.deleteById(id);
    }

    @Override
    public int save(IntegralGradeSaveReqVO reqVO) {
        IntegralGradePO savePO = BeanUtil.copyProperties(reqVO, IntegralGradePO.class);

        savePO.setDeleted(false);
        savePO.setUpdateTime(LocalDateTime.now());
        savePO.setCreateTime(LocalDateTime.now());
        return integralGradeMapper.insert(savePO);
    }

    @Override
    public IntegralGradeQueryRespVO queryById(Long id) {
        LambdaQueryWrapper<IntegralGradePO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IntegralGradePO::getId, id)
                .eq(IntegralGradePO::getDeleted, Boolean.FALSE);
        return BeanUtil.copyProperties(integralGradeMapper.selectById(wrapper), IntegralGradeQueryRespVO.class);
    }
}
